<cfcomponent extends="Controller">	
	<cffunction name="updateUser">
		<cfscript>
			updateMessage = "";
			createMessage = "";			

			if(StructKeyExists(PARAMS, "update")) {
				updateMessage &= "[div][strong]The following users have been successfully updated![/strong][ul]";

				for(id IN PARAMS.update) {
					PARAMS.update[id].mainPhone = Replace(PARAMS.update[id].mainPhone, ",", "", "All");
					PARAMS.update[id].secondaryPhone = Replace(PARAMS.update[id].secondaryPhone, ",", "", "All");
					users = Model('user').updateByKey(key=id, properties=PARAMS.update[id]);

					updateMessage &= "[li]#PARAMS.update[id].firstName# #PARAMS.update[id].lastName#[/li]";
				}
				
				updateMessage &= "[/ul][/div]";
			}

			if(StructKeyExists(PARAMS, "save")) {
				createMessage &= '[div][strong]The following users have been successfully created![/strong] (Reminder: The default password is "Welcome" and can be changed when logging in for the first time!)[ul]';

				for(id IN PARAMS.save) {
					isEmpty = true;

					PARAMS.save[id].mainPhone = Replace(PARAMS.save[id].mainPhone, ",", "", "All");
					PARAMS.save[id].secondaryPhone = Replace(PARAMS.save[id].secondaryPhone, ",", "", "All");

					for(key IN PARAMS.save[id]) {
						if(PARAMS.save[id][key] IS NOT "")
							isEmpty = false;
					}

					if(NOT isEmpty) {				
						PARAMS.save[id].login = ListAppend(PARAMS.save[id].firstName, PARAMS.save[id].lastName, '.');
						PARAMS.save[id].password = "welcome";
						users = Model("user").create(PARAMS.save[id]);

						createMessage &= "[li]#PARAMS.save[id].firstName# #PARAMS.save[id].lastName#[/li]";
					}
				}
				createMessage &= "[/ul][/div]";
			}
				
			adminMessage = Replace(Replace(updateMessage & createMessage, "[", "<", "All"), "]", ">", "All");
			flashInsert(admin=adminMessage);
			renderWith(users);
		</cfscript>
	</cffunction>
	
	<cffunction name="deleteUser">
		<cfscript>
			user = model("user").findByKey(PARAMS.key);
			flashInsert(admin=Replace(Replace("#user.name# [strong]has been successfully deleted![/strong]", "[", "<", "All"), "]", ">", "All"));
			user.delete();
			renderWith(user);
		</cfscript>
	</cffunction>
</cfcomponent>